package com.tanhua.sso.utils;

/**
 * @author 阿离(灰原)
 * @version 1.0
 * @date 2023/8/27 下午 05:03
 */

import com.baomidou.mybatisplus.extension.api.R;

import java.util.HashMap;
import java.util.Map;

/**
 * 统一返回数据返回给前端
 *
 * @param <T>
 */

public class Result<T> {
    //    200成功,500失败
    private Integer code;
    private T data;
    private String message;
    private Map map = new HashMap();

    /**
     * 成功响应方法
     *
     * @param object
     * @param <T>
     * @return
     */
    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<T>();
        result.code = 200;
        result.data = object;
        return result;
    }

    public static <T> Result<T> error(String message) {
        Result<T> result = new Result<T>();
        result.code = 500;
        result.message = message;
        return result;
    }

    public Result<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }
}
